package com.sgb.kjwl.viewmodel.lookingforAJob;


import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.PackersBusinessScopeEntity;
import com.sgb.kjwl.model.entity.PackersEntity;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.packers.PackersActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MLog;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class WorksModel extends BaseViewModel {
    private PackersActivity activity;
    private HomeRepertory repertory;

    public WorksModel(PackersActivity activity, HomeRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    public void getInfo(String id) {
        DialogHelper.showProgressDialog(activity, null, "获取信息中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPackerAPI().getPackerDetail(id).enqueue(new Callback<BaseEntity<PackersEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<PackersEntity>> call, Response<BaseEntity<PackersEntity>> response) {
                if (response.body() == null) return;
                DialogHelper.dismissProgressDialog();
                activity.showPackersDetail(response.body().getData());
            }

            @Override
            public void onFailure(Call<BaseEntity<PackersEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, t.getMessage());
            }
        });

        APIManager.getInstance().getPackerAPI().getPackerScope(id).enqueue(new Callback<BaseEntity<PackersBusinessScopeEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<PackersBusinessScopeEntity>> call, Response<BaseEntity<PackersBusinessScopeEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                activity.showPackersBusinessScope(response.body().getData());
            }

            @Override
            public void onFailure(Call<BaseEntity<PackersBusinessScopeEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, t.getMessage());
            }
        });
    }
}
